<?php
// +----------------------------------------------------------------------
// | Siteplus [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://www.brsttech.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Pillar <service@brsttech.com>
// +----------------------------------------------------------------------
namespace app\admin\model;
use think\Model;
use backup\Backup;

class Db extends Model{

    
    /**
     * 返回表结构
     * @access public
     */
    public function TableLists(){
        return $this->query('SHOW TABLE STATUS');
    }

    /**
     * 获取数据表
     * @access public
     * @return string
     */
    public function GetTable(){
        $result = $this->TableLists();
        foreach ($result as $value) {
            $tables[] = $value['Name'];
        }
        return implode('`,`',$tables);
    }

    /**
     * 数据库优化
     * @access public
     */
    public function optimized(){
        $tables = $this->GetTable();
        if($this->query("OPTIMIZE TABLE `{$tables}`")){
            return ['code' => 0,'message' => '数据库优化成功'];
        } else {
            return ['code' => 1,'message' => '数据库优化失败，请稍后重试！'];
        }
    }

    /**
     * 数据库修复
     * @access public
     */
    public function repair(){
        $tables = $this->GetTable();
        if($this->query("REPAIR TABLE `{$tables}`")){
            return ['code' => 0,'message' => '数据库修复成功'];
        } else {
            return ['code' => 1,'message' => '数据库修复失败，请稍后重试！'];
        }
    } 
}